# -*- coding:utf-8 -*-

import os, sys
root = os.path.abspath(os.path.dirname(__file__))
projectRoot = os.path.dirname(root)
sys.path.insert(0, projectRoot)

import models, service

models.User.clear()
models.Action.clear()
models.Case.clear()
models.Company.clear()
models.Contact.clear()

company1 = models.Company.addCompany(u'分公司', models.Company.TYPE_BRANCH)
company2 = models.Company.addCompany(u'公估公司aa', models.Company.TYPE_ASSESS)
company3 = models.Company.addCompany(u'保险公司', models.Company.TYPE_INSURANCE)
company4 = models.Company.addCompany(u'分公司2', models.Company.TYPE_BRANCH)

user0id = models.User.addUser('admin', '123456', 'admin', None, models.User.TYPE_ADMIN)
user1id = models.User.addUser('chief', '123456', 'chief', company1, models.User.TYPE_CHIEF)
user2id = models.User.addUser('common', '123456', 'common', company1)
user3id = models.User.addUser('assess', '123456', 'assess', company2)
user4id = models.User.addUser('insurance', '123456', 'insurance', company3)

user = models.User.getUserByNamePass('chief', '123456')
user1 = models.User.getById(user1id)
user2 = models.User.getById(user2id)
user3 = models.User.getById(user3id)
user4 = models.User.getById(user4id)

print user == user1

case1 = service.Operation.createCase(company1, user1id, 1, u'北京', 'hello', '2015-9-9', 0)
service.Operation.pushCase(case1, user1)
service.Operation.receiveCase(case1, user2)
service.Operation.undoCase(case1, user2)
service.Operation.receiveCase(case1, user2)
service.Operation.returnCase(case1, user1)
service.Operation.pushCase(case1,user1)
service.Operation.receiveCase(case1,user2)
service.Operation.modifyCase(case1, user2, u'北京', 'hello', '2015-9-9', 3)
service.Operation.pushCase(case1, user2)
service.Operation.receiveCase(case1, user3)
service.Operation.pushCase(case1, user3)
service.Operation.receiveCase(case1, user4)
service.Operation.pushCase(case1, user4)

case2 = service.Operation.createCase(company1, user1id, 0, u'北京', 'hello', '2015-9-9', 0)
service.Operation.pushCase(case2, user1)
service.Operation.receiveCase(case2, user2)
service.Operation.undoCase(case2, user2)
service.Operation.receiveCase(case2, user2)
service.Operation.returnCase(case2, user1)
service.Operation.pushCase(case2, user1)
service.Operation.receiveCase(case2, user2)
service.Operation.modifyCase(case2, user2, u'北京', 'hello', '2015-9-9', 3)
service.Operation.pushCase(case2, user2)
service.Operation.receiveCase(case2, user4)
service.Operation.pushCase(case2, user4)

case3 = service.Operation.createCase(company1, user1id, 0, u'北京', 'hello3', '2015-9-9', 0)

# print service.Action.getFormatActions(case2)

# print service.Case.getFinishedFormatCases(company1)

# print models.Case.getLastestOperateTime()

# print service.Excel.getFinishedCasesExcelPath(company1)

# print models.Case.getUnfinishedCasesCount(0, company1)
# print models.Case.getFinishedCasesCount()
# print models.Case.getFinishedCasesValueSum()

# print service.Case.getStatistics()
# print service.Case.getStatistics(company1)


